var SmartyAjax = {
  update: function(update_id, url, method, params, callback) {
      if (params.length != 0) {
	params += "&";	
     }
    var myAjax = new Ajax.Updater(
      update_id,
      url,
      {
        method: method,
        parameters: params+"ajaxrandom="+Math.random(),
        onComplete: callback
      });
  },

  call: function(url, method, params, callback, params_func) {
    if (params_func) {
      if (params.length != 0) params += "&";
      params += $H(params_func()).toQueryString();
    }
    var myAjax = new Ajax.Request(
      url,
      {
        method: method,
        parameters: params,
        onComplete: callback
      });
  },

  updatesubmit: function(form, update_id, url, method, params, callback) {
  	var myAjax = new Ajax.Updater(
      		update_id,
  		url,
  		{
  			method: method,
  			parameters: Form.serialize(form.id),
		        onComplete: callback
  		});
  }

}


SmartyAjax.GlobalHandlers = {
	onCreate: function() {
		SmartyAjax.Process.show();
	},

	onComplete: function() {
		if(Ajax.activeRequestCount == 0){
  		SmartyAjax.Process.hide();
		}
	}
};

Ajax.Responders.register(SmartyAjax.GlobalHandlers);


SmartyAjax.Process = {
  S_PROCESS: "<img src='images/await.gif' />'",

  show: function() {
    if (!this.process) {
      this.process = $("ajax-process");
      if (!this.process) return;
    }
    var top = window.pageYOffset ? window.pageYOffset : document.documentElement ? document.documentElement.scrollTop : document.body.scrollTop;
    this.process.style.top = top + "px";
    this.process.innerHTML = this.S_PROCESS;
    this.process.style.display = "inline";
  },

  hide: function() {
    if (!this.process) {
      this.process = $("ajax-process");
      if (!this.process) return;
    }
    this.process.style.display = "none";
  }
}

